<?php
	include_once("login.php");

	$conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db)
		or die('Did not connect: ' . mysqli_connect_error());
		
	$stmt = mysqli_prepare($conn, "INSERT INTO scores VALUES (?, ?, ?, ?)");

	mysqli_stmt_bind_param($stmt, 'ssbi', $username, $quizname, $score, $totalNum);

	$username = $_GET["username"];
	$username = mysqli_real_escape_string($conn, $username);
	$quizname = $_GET["quizname"];
	$quizname = mysqli_real_escape_string($conn, $quizname);
	$totalNum = $_GET["totalQ"];
	$totalNum = mysqli_real_escape_string($conn, $totalNum);

	// Get binary data
	$file = "php://input";
	$fp = fopen($file,"r");
	$size = 0;

	while ($score = fread($fp, 128)) {
		$size += strlen($score);
		mysqli_stmt_send_long_data($stmt, 2, $score);
	}

	mysqli_stmt_execute($stmt) 
		or die ('Statement error: ' . mysqli_connect_error());

	print "Data of size ($size bytes) was added to the Scores.\n";

	mysqli_stmt_close($stmt);
	mysqli_close($conn);
	fclose($fp);
?>
